package edu.sctu.zcy.month201505.day20150517;

import java.util.*;

/**
 * Created by user24 on 2015/5/17.
 */
public class TextOne extends TextMore {

    //    int m = 0;
//    int n = 0;
//    int j = 0;
//    int k = 0;
//    int l = 0;
//    int p = 0;
    List<TeaCher> teaCherslist = new ArrayList<>();
//   static List<Student> students2 = new ArrayList<>();


    public void getTercherInfo() {

        teaCherslist = sotrNumber();

        System.out.println("按教师编号排序后：");

        for (int i = 0; i < teaCherslist.size(); i++) {

            System.out.println("编号：" + teaCherslist.get(i).getNumber());
            System.out.println("姓名：" + teaCherslist.get(i).getName());
            System.out.println("职称：" + teaCherslist.get(i).getTechnicalTitle());
            System.out.println("性别：" + teaCherslist.get(i).getSex());
            System.out.println("所授课程：" + teaCherslist.get(i).getCourse());

            for (int j = 0; j < teaCherslist.get(i).getStudents().size(); j++) {

                System.out.println("所教学生：" + teaCherslist.get(i).getStudents().get(j).getName());
            }
            System.out.println();

        }
    }


    public List<Student> getStudent(int code, List<Student> students) {

//        studentlist = sortStudent();
//
//        for(Student studentsOne : studentlist){
//
//            if(Integer.parseInt(studentsOne.getScore()) > code){
//
//                students2.add(studentsOne);
//
//            }
//        }

        List<Student> students1 = new ArrayList<>();
        for (Student student : students) {
            if (Integer.parseInt(student.getScore()) > code) {

                students1.add(student);
            }
        }
        return students1;
    }

    //    List<Student> studentlist = new ArrayList<>();


    public void getCode(InterFaceStudent interFaceStudent) {

        teaCherslist = pritCoded();

        List<Student> students = new ArrayList<>();

        for (int i = 0; i < teaCherslist.size(); i++) {

            for (int j = 0; j < teaCherslist.get(i).getStudents().size(); j++) {

                students.add(teaCherslist.get(i).getStudents().get(j));
            }

            interFaceStudent.getInfo(students);


        }
    }

//    public void getCourse(Student[] students) {
//
//
//        for (int i = 0; i < students.length; i++) {
//
//            TextCourse[] textCourses = students[i].setCourseOne();
//
//            if (textCourses[i] != null) {
//
//                System.out.println(students[i].getName() + "选择的课程有：" + textCourses[i].course1[0] + "  " +
//                        textCourses[i].course1[1] + "  " + textCourses[i].course1[2]);
//                if (textCourses[i].course1[0].equals("java")) {
//
//                    m++;
//                }
//
//                if (textCourses[i].course1[1].equals("大学英语")) {
//                    n++;
//                }
//
//                if (textCourses[i].course1[2].equals("数据结构")) {
//                    j++;
//                }
//
//                if (textCourses[i].course1[0].equals("大学计算机")) {
//                    k++;
//                }
//
//                if (textCourses[i].course1[1].equals("高等数学")) {
//                    l++;
//                }
//                if (textCourses[i].course1[2].equals("大学语文")) {
//                    p++;
//                }
//            }
//
//        }
//         int[] num = new int[]{m,n,j,k,l,p};
//         Arrays.sort(num);
//        System.out.println(num[num.length-1]);

//        int e = Math.max(Math.max(Math.max(Math.max(Math.max(m, n), j), k), l), p);
//        if(e == m){
//            System.out.println("学生所选的共同课程最多的为:java");
//        }else if(e == n){
//            System.out.println("学生所选的共同课程最多的为:大学英语");
//            for (int i = 0; i < students.length; i++) {
//                if(students[i].setCourseOne()[i].course1[0].equals("大学英语")){
//                    System.out.println("选择大学英语的学生有："+students[i].getName());
//                }
//                if(students[i].setCourseOne()[i].course1[1].equals("大学英语")){
//                    System.out.println("选择大学英语的学生有："+students[i].getName());
//                }
//
//                if(students[i].setCourseOne()[i].course1[2].equals("大学英语")){
//                    System.out.println("选择大学英语的学生有："+students[i].getName());
//                }
//            }
//
//        }else if(e == j){
//            System.out.println("学生所选的共同课程最多的为:数据结构");
//            for (int i = 0; i < students.length; i++) {
//                if(students[i].setCourseOne()[i].course1[0].equals("数据结构")){
//                    System.out.println("选择数据结构的学生有："+students[i].getName());
//                }
//                if(students[i].setCourseOne()[i].course1[1].equals("数据结构")){
//                    System.out.println("选择数据结构的学生有："+students[i].getName());
//                }
//
//                if(students[i].setCourseOne()[i].course1[2].equals("数据结构")){
//                    System.out.println("选择数据结构的学生有："+students[i].getName());
//                }
//            }
//
//        }else if(e == k){
//            System.out.println("学生所选的共同课程最多的为:大学计算机");
//        }else if(e == l){
//            System.out.println("学生所选的共同课程最多的为:高等数学");
//
//        }else{
//            System.out.println("学生所选的共同课程最多的为:大学语文");
//
//        }
//


//  final int[] num = new int[]{m,n,j,k,l,p};
//       int change = 0;
//        for (int i = 0; i < num.length; i++) {
//            for (int o = 0; o < num.length-1; o++) {
//                if(num[o] < num[o+1]){
//                    change = num[o];
//                    num[o] = num[o+1];
//                    num[o+1] = change;
//                }
//            }
//
//        }
//        System.out.println(num[0]);

//    }

    public List<Student> getStudentScoreInfo(int score) {

        List<Student> student0 = new TextOne().sortStudent();

        List<Student> student1 = new ArrayList<>();


//       System.out.println(studentList0ne.size());

        for (Student student : student0) {

            if (Integer.parseInt(student.getScore()) >= score) {
                student1.add(student);
                student.is_sanHao = true;
            }
        }
        return student1;
    }


//    private class Address{
//        public String city;
//        public String district;
//        public String address;
//    }

    public HashMap<String, List<String>> getAllStudentAddress() {

//        List<String> addressList = new ArrayList<>();
//
//
//        List<Student> studentList = new TextOne().sortStudent();
//
//        for(Student student : studentList){
//
//            String address = student.getAddress();// 成都市青羊区
//            addressList.add(address);
//        }
//
//        return  addressList;

        HashMap<String, List<String>> studentAddress = new HashMap<String, List<String>>();
        List<Student> students = new TextOne().sortStudent();

        List<String> listDistict = new ArrayList<>();
        List<String> listDistictOne = new ArrayList<>();
        List<String> listDistictTwo = new ArrayList<>();
        List<String> listDistictThree = new ArrayList<>();

        for (Student student : students) {

            if (student.getAddress().contains("成都市")) {
                listDistict.add(student.getAddress().substring(3));

            }
            studentAddress.put("成都市", listDistict);

            if (student.getAddress().contains("资阳市")) {
                listDistictOne.add(student.getAddress().substring(3));

            }
            studentAddress.put("资阳市", listDistictOne);

            if (student.getAddress().contains("北京市")) {
                listDistictTwo.add(student.getAddress().substring(3));


            }
            studentAddress.put("北京市", listDistictTwo);

            if (student.getAddress().contains("浙江市")) {
                listDistictThree.add(student.getAddress().substring(3));

            }
            studentAddress.put("浙江市", listDistictThree);
        }


//        Set<String> listCity = new HashSet<>();
//
//        for (int i = 0; i < students.size(); i++) {
//
//            listCity.add(students.get(i).getAddress().substring(0,3));
//
//        }

        return studentAddress;
    }

    public void getCity(String city) {

        HashMap<String, List<String>> studentAddress = getAllStudentAddress();

//        System.out.println(studentAddress.get("成都市"));
//        System.out.println(studentAddress.get("资阳市"));
//        System.out.println(studentAddress.get("北京市"));
//        System.out.println(studentAddress.get("浙江市"));

        List<Student> students = new TextOne().sortStudent();

        Set<String> key = studentAddress.keySet();

        for (String key1 : key) {

            if (city.contains(key1)) {
                System.out.println(key1 + "的学生信息为：");

                printStudentsInfo(key1);
            }
        }
    }


//        while (key.hasNext()) {
//
//           System.out.println(key.next());
//            if (key.next().equals(city)) {
//                System.out.println(key.next());
//            }
//        }


    public void getDistrict(String district) {

        HashMap<String, List<String>> studentAddress = getAllStudentAddress();


//        Iterator value = studentAddress.entrySet().iterator();
//
//        while (value.hasNext()){
//
//            System.out.println(value);
//            if(value.next().equals(district)){
//            }
//
//        }
//        System.out.println(students.size());


        Set<Map.Entry<String, List<String>>> key = studentAddress.entrySet();


        System.out.println(district + "地区的学生信息：");

        for (Map.Entry<String, List<String>> key1 : key) {


            for (String district1 : key1.getValue()) {

                if (district.contains(district1)) {
                    printStudentsInfo(district1);


                }
            }
        }


//        for (Map.Entry<String, List<String>> key1 : key) {
//
//            for (int j  = 0; j < key1.getValue().size(); j++) {
//
//                if (key1.getValue().get(j).contains(district)) {
//                    for (int i = 0; i < students.size(); i++) {
//
//                        if (students.get(i).getAddress().contains((CharSequence) key1.getValue())) {
//                            System.out.println("姓名：" + students.get(i).getName() + "  年龄："
//                                    + students.get(i).getAge() + "  性别："
//                                    + students.get(i).getSex() + "  成绩：" + students.get(i).getScore());
//                        }
//
//
//                    }
//                }
//
//            }
//
//        }
    }


    public void getAddress(String address) {

        HashMap<String, List<String>> studentAddress = getAllStudentAddress();

        Set<Map.Entry<String, List<String>>> address1 = studentAddress.entrySet();

        System.out.println(address + "的学生信息为：");

        for (Map.Entry<String, List<String>> address2 : address1) {

            for (int i = 0; i < address2.getValue().size(); i++) {

                if (address.contains(address2.getKey()) && address.contains(address2.getValue().get(i))) {

                    printStudentsInfo(address);


                }
//                else {
//                    System.out.println("不存在你想要找的学生！");
//                    break lable;
//                }

                }

            }


        }


    public void printStudentsInfo(String district) {

        List<Student> students = new TextOne().sortStudent();

        for (int i = 0; i < students.size(); i++) {

            if ((students.get(i).getAddress().contains(district))) {

                System.out.println("姓名：" + students.get(i).getName() + "  年龄："
                        + students.get(i).getAge() + "  性别："
                        + students.get(i).getSex() + "  成绩：" + students.get(i).getScore() + "  地址:"
                        + students.get(i).getAddress());
            }

        }

    }


}


//                switch (textCourses[i].course1[0]) {
//
//                    case "数据结构":
//                        System.out.println("数据结构");
//                        break;
//                    case "高等数学":
//                        System.out.println("高等数学");
//                        break;
//                    case "大学英语":
//                        System.out.println("大学英语");
//                        break;
//                    case "java":
//                        System.out.println("java");
//                        break;
//                    case "大学语文":
//                        System.out.println("大学语文");
//                        break;
//                    case "大学计算机":
//                        System.out.println("大学计算机");
//                        break;
//
//                }



